package com.example.userdemo.util;


import lombok.Data;

import javax.annotation.Resource;

@Data
public class Response<T> {
    private String code;
    private String messge;
    private T data;

    public Response(){};

    public static<T> Response<T> success(T data){
        Response<T> res = new Response<>();
        res.code = ErrorCode.OK.code;
        res.data =data;
        return res;
    }

    public static<T> Response<T> failure(ErrorCode code){
        Response<T> res= new Response<>();
        res.code = code.code;
        res.messge = code.description;
        return res;
    }

    public static<T> Response<T> failure(ErrorCode code, String msg){
        Response<T> res = new Response<>();
        res.code = code.code;
        res.messge = msg;
        return res;
    }

    public Response(String  code, String messge){
        this.code = code;
        this.messge = messge;
    }

    public Response(String code, String messge, T data){
        this.code = code;
        this.messge = messge;
        this.data =data;
    }
}
